import Vue from 'vue';
import Router from 'vue-router';

Vue.use(Router);

const routes = [
  {
    path: '*',
    redirect: '/homeList'
  },
  // {
  //   name: 'user',
  //   component: () => import('../view/index/index'),
  //   meta: {
  //     title: '会员中心'
  //   }
  // },
  // {
  //   name: 'cart',
  //   component: () => import('../view/order/index'),
  //   meta: {
  //     title: '购物车'
  //   }
  // },
  // {
  //   name: 'goods',
  //   component: () => import('../view/upload/index'),
  //   meta: {
  //     title: '商品详情'
  //   }
  // },

  {
    name: 'homeList',
    component: () => import('../view/home/index'),
    meta: {
      title: '上传地址列表'
    }
  },
  {
    name: 'uploadImg',
    component: () => import('../view/home/upload'),
    meta: {
      title: '上传图片'
    }
  },
  {
    name: 'order',
    component: () => import('../view/my/order/list'),
    meta: {
      title: '我的订单'
    }
  },
  {
    name: 'orderDetail',
    component: () => import('../view/my/order/detail'),
    meta: {
      title: '订单详情'
    }
  },

];

// add route path
routes.forEach(route => {
  route.path = route.path || '/' + (route.name || '');
});

const router = new Router({ routes });

router.beforeEach((to, from, next) => {
  const title = to.meta && to.meta.title;
  if (title) {
    document.title = title;
  }
  next();
});

export {
  router
};
